#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<unordered_map>
#include<set>
#include<vector>

using namespace std;

vector<int> avoidFlood(vector<int>& rains) {
    vector<int> res(rains.size(), 1);
    unordered_map<int, int> water;
    set<int> zero;

    for (int i = 0; i < rains.size(); i++)
    {
        int r = rains[i];
        if (r == 0)
        {
            zero.insert(i);
            continue;
        }

        if (water.count(r) != 0)
        {
            auto it = zero.lower_bound(water[r]);
            if (it == zero.end())
                return {};
            res[*it] = rains[i];
            zero.erase(it);
        }
        water[r] = i;
        res[i] = -1;
    }
    return res;
}

int main()
{
    vector<int> v = { 69,0,0,0,69 };
    avoidFlood(v);
	return 0;
}